#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(
    default_visibility = ["//visibility:public"],
)

cc_library(
    name = "algorithm",
    hdrs = ["algorithm.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":confidence_interval_cc_proto",
        ":numerical-mechanisms",
        ":util",
        "//differential_privacy/base:status",
        "//differential_privacy/base:statusor",
        "//differential_privacy/proto:data_cc_proto",
        "//differential_privacy/proto:summary_cc_proto",
        "//differential_privacy/proto:util-lib",
        "@com_google_absl//absl/memory",
    ],
)

cc_test(
    name = "algorithm_test",
    srcs = ["algorithm_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "algorithm-stochastic-dp_test",
    timeout = "eternal",
    srcs = ["algorithm-stochastic-dp_test.cc"],
    copts = ["-Wno-sign-compare"],
    shard_count = 16,
    deps = [
        ":approx-bounds",
        ":bounded-mean",
        ":bounded-standard-deviation",
        ":bounded-sum",
        ":bounded-variance",
        ":count",
        ":numerical-mechanisms-testing",
        ":order-statistics",
        "//differential_privacy/testing:sequence",
        "//differential_privacy/testing:stochastic_tester",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "binary-search",
    hdrs = ["binary-search.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":numerical-mechanisms",
        "//differential_privacy/base:percentile",
        "//differential_privacy/base:status",
        "//differential_privacy/proto:util-lib",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_test(
    name = "binary-search_test",
    srcs = ["binary-search_test.cc"],
    copts = ["-Wno-sign-compare"],
    shard_count = 6,
    deps = [
        ":algorithm",
        ":binary-search",
        ":numerical-mechanisms",
        ":numerical-mechanisms-testing",
        ":util",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/random:distributions",
    ],
)

cc_library(
    name = "order-statistics",
    hdrs = ["order-statistics.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":binary-search",
        ":bounded-algorithm",
        "//differential_privacy/base:percentile",
        "//differential_privacy/base:status",
    ],
)

cc_test(
    name = "order-statistics_test",
    srcs = ["order-statistics_test.cc"],
    copts = ["-Wno-sign-compare"],
    shard_count = 3,
    deps = [
        ":numerical-mechanisms-testing",
        ":order-statistics",
        ":util",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/random:distributions",
    ],
)

cc_library(
    name = "bounded-sum",
    hdrs = ["bounded-sum.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":bounded-algorithm",
        ":numerical-mechanisms",
        "//differential_privacy/base:status",
        "//differential_privacy/proto:summary_cc_proto",
        "@com_google_absl//absl/memory",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_library(
    name = "bounded-mean",
    hdrs = ["bounded-mean.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":bounded-algorithm",
        ":numerical-mechanisms",
        "//differential_privacy/base:status",
        "//differential_privacy/proto:summary_cc_proto",
        "@com_google_absl//absl/random:distributions",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_library(
    name = "bounded-variance",
    hdrs = ["bounded-variance.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":approx-bounds",
        ":bounded-algorithm",
        ":numerical-mechanisms",
        "//differential_privacy/proto:util-lib",
        "@com_google_absl//absl/memory",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_library(
    name = "bounded-standard-deviation",
    hdrs = ["bounded-standard-deviation.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":bounded-algorithm",
        ":bounded-variance",
        ":numerical-mechanisms",
        "@com_google_absl//absl/memory",
    ],
)

cc_test(
    name = "bounded-sum_test",
    srcs = ["bounded-sum_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":bounded-sum",
        ":numerical-mechanisms",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "//differential_privacy/proto:util-lib",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/memory",
    ],
)

cc_test(
    name = "bounded-mean_test",
    srcs = ["bounded-mean_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":bounded-mean",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "bounded-variance_test",
    srcs = ["bounded-variance_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":bounded-variance",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/random:distributions",
    ],
)

cc_test(
    name = "bounded-standard-deviation_test",
    srcs = ["bounded-standard-deviation_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":bounded-standard-deviation",
        ":distributions",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/random:distributions",
    ],
)

cc_library(
    name = "count",
    hdrs = ["count.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":numerical-mechanisms",
        "//differential_privacy/proto:summary_cc_proto",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_test(
    name = "count_test",
    srcs = ["count_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":count",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "//differential_privacy/proto:data_cc_proto",
        "//differential_privacy/proto:summary_cc_proto",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_library(
    name = "util",
    srcs = ["util.cc"],
    hdrs = ["util.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        "//differential_privacy/base:logging",
        "//differential_privacy/base:status",
        "//differential_privacy/base:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "util_test",
    srcs = ["util_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":distributions",
        ":numerical-mechanisms-testing",
        ":util",
        "//differential_privacy/base:status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "distributions",
    srcs = ["distributions.cc"],
    hdrs = ["distributions.h"],
    copts = ["-Wno-sign-compare"],
    visibility = ["//visibility:private"],
    deps = [
        ":rand",
        ":util",
        "//differential_privacy/base:statusor",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "distributions_test",
    srcs = ["distributions_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":distributions",
        ":numerical-mechanisms-testing",
        ":util",
        "//differential_privacy/base:status",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/memory",
    ],
)

cc_library(
    name = "numerical-mechanisms",
    hdrs = ["numerical-mechanisms.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":confidence_interval_cc_proto",
        ":distributions",
        ":util",
        "//differential_privacy/base:status",
    ],
)

cc_test(
    name = "numerical-mechanisms_test",
    srcs = ["numerical-mechanisms_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":distributions",
        ":numerical-mechanisms",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "approx-bounds_test",
    srcs = ["approx-bounds_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":approx-bounds",
        ":numerical-mechanisms-testing",
        "//differential_privacy/base/testing:proto_matchers",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
        "@com_google_absl//absl/memory",
    ],
)

cc_test(
    name = "bounded-algorithm_test",
    srcs = ["bounded-algorithm_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":bounded-algorithm",
        "//differential_privacy/base/testing:status_matchers",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "numerical-mechanisms-testing",
    testonly = 1,
    hdrs = ["numerical-mechanisms-testing.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":confidence_interval_cc_proto",
        ":distributions",
        ":numerical-mechanisms",
        "@com_google_googletest//:gtest",
        "//differential_privacy/base:statusor",
    ],
)

cc_test(
    name = "numerical-mechanisms-testing_test",
    srcs = ["numerical-mechanisms-testing_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":numerical-mechanisms-testing",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "approx-bounds",
    hdrs = ["approx-bounds.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        "//differential_privacy/base:status",
        "//differential_privacy/proto:util-lib",
        "@com_google_protobuf//:cc_wkt_protos",
    ],
)

cc_library(
    name = "bounded-algorithm",
    hdrs = ["bounded-algorithm.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":algorithm",
        ":approx-bounds",
        "//differential_privacy/base:status",
    ],
)

proto_library(
    name = "confidence-interval_proto",
    srcs = ["confidence-interval.proto"],
)

cc_proto_library(
    name = "confidence_interval_cc_proto",
    deps = [":confidence-interval_proto"],
)

cc_library(
    name = "rand",
    srcs = ["rand.cc"],
    hdrs = ["rand.h"],
    copts = ["-Wno-sign-compare"],
    deps = [
        "//differential_privacy/base:logging",
        "@boringssl//:crypto",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_test(
    name = "rand_test",
    srcs = ["rand_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":rand",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "distributions_benchmark_test",
    srcs = ["distributions_benchmark_test.cc"],
    copts = ["-Wno-sign-compare"],
    deps = [
        ":distributions",
        "@com_google_benchmark//:benchmark_main",
        "@com_google_absl//absl/strings:str_format",
    ],
)
